package com.lwb.eduservice.controller;


import com.alibaba.excel.write.handler.RowWriteHandler;
import com.lwb.commonutils.Row;
import com.lwb.eduservice.entity.EduCourse;
import com.lwb.eduservice.entity.vo.CourseInfoVo;
import com.lwb.eduservice.entity.vo.CoursePublishVo;
import com.lwb.eduservice.service.EduCourseService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-11-17
 */
@RestController
@RequestMapping("/eduservice/edu-course")
public class EduCourseController {

    @Autowired
    private EduCourseService eduCourseService;

    //添加课程基本信息的方法
    @ApiOperation("添加课程基本信息的方法")
    @PostMapping("addCourseInfo")
    public Row addCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
        String id = eduCourseService.addCourseInfo(courseInfoVo);
        return Row.SUCCESS().data("courseId",id);
    }

    //根据课程id查询课程信息
    @ApiOperation("根据课程id查询课程信息")
    @GetMapping("getCourseInfo/{courseId}")
    public Row getCourseInfo(@PathVariable String courseId){
        CourseInfoVo courseInfoVo = eduCourseService.getCourseInfo(courseId);
        return Row.SUCCESS().data("courseInfoVo",courseInfoVo);
    }

    //修改课程信息
    @ApiOperation("修改课程信息")
    @PostMapping("updateCourseInfo")
    public Row updateCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
        eduCourseService.updateCourseInfo(courseInfoVo);
        return Row.SUCCESS();
    }

    //根据课程id查询课程确认信息
    @GetMapping("getPublishCourseInfo/{id}")
    public Row getPublishCourseInfo(@PathVariable String id) {
        CoursePublishVo coursePublishVo = eduCourseService.publishCourseInfo(id);
        return Row.SUCCESS().data("coursePublish",coursePublishVo);
    }

    //课程最终发布
    //根据课程id查询课程确认信息
    @GetMapping("publishCourse/{id}")
    public Row publishCourse(@PathVariable String id) {
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(id);
        eduCourse.setStatus("Normal");
        eduCourseService.updateById(eduCourse);
        return Row.SUCCESS();
    }

    //查询所有课程信息
    @GetMapping("getListCourse")
    public Row getListCourse(){
        List<EduCourse> list = eduCourseService.list(null);
        return Row.SUCCESS().data("list",list);
    }

    //删除课程
    @DeleteMapping("{courseId}")
    public Row deleteCourse(@PathVariable String courseId){
        eduCourseService.deleteCourse(courseId);
        return Row.SUCCESS();
    }
}

